# Use an official Node.js runtime as the base image
FROM node:23 AS build-stage

RUN ln -s /sbin/runc /usr/bin/runc

# Set the working directory inside the container
WORKDIR /app

# Copy package.json and package-lock.json (or yarn.lock)
COPY package*.json ./
# COPY yarn.lock ./

# Install dependencies
RUN yarn

# 复制项目文件
COPY . .

# Build the NestJS application (if you're building for production)
RUN npm run build

# Expose the port your app runs on (default is 3000 for NestJS)
# production stage
FROM node:alpine AS production-stage

COPY --from=build-stage /app/dist /app

COPY --from=build-stage /app/package.json /app
COPY --from=build-stage /app/assets /app/assets
COPY --from=build-stage /app/public /app/public
# COPY --from=build-stage /app/public_key.pem /app/src
# COPY --from=build-stage /app/promoptwords.txt /app/src

WORKDIR /app

RUN npm config set registry https://registry.npmmirror.com/

RUN yarn

EXPOSE 3000

CMD ["node", "/app/src/main.js"]